<template>
  <div>
    <el-card style="line-height: 30px; margin-bottom: 10px">
      <div style="display: flex ; align-items: center">
        <span>负责活动:</span><span style="color: #3BB201">{{activity}}</span>
        <span style="margin-left: 20px">活动地点:</span><span style="color: #3BB201">{{museum}}</span>
      </div>
    </el-card>
    <div class="card" style="margin-bottom: 10px">
      <el-table :data="tableData" style="width: 100%" stripe :header-cell-style="{backgroundColor: 'aliceblue', color: '#666'}" @selection-change="handleSelectionChange">
        <el-table-column prop="name" label="负责人名称"/>
        <el-table-column prop="title" label="职位"/>
        <el-table-column prop="museum" label="负责场地"/>
        <el-table-column prop="activity" label="负责活动"/>
        <el-table-column prop="phone" label="负责电话"/>
        <el-table-column prop="email" label="负责邮箱"/>
      </el-table>
    </div>
    <div style="margin: 10px 0">
      <div class="example-pagination-block">
        <el-pagination
            @current-change="handleCurrentChange;"
            :current-page="pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="pageSize"
            layout="total, prev, pager, next"
            :total="total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import {handleCurrentChange} from "element-plus/es/components/tree/src/model/util";
import request from "@/utils/request";
import {ElMessage, ElMessageBox} from "element-plus";
import E from "wangeditor";
import hljs from "highlight.js";
import user from "@/views/manager/User.vue";

export default {
  name: "job" ,
  data() {
    return {
      user: JSON.parse(localStorage.getItem('honey-user') || '{}'),
      headFormVis: false,
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      title: '',
      name: '',
      museum: '',
      activity: '',

      rules: {

      }
    }
  },
  created() {
    this.selectById(this.user.id)
    console.log("负责人数据:", this.user);
  },
  methods: {
    handleCurrentChange,
    selectById(id) {
      request.get(`/head/selectById/${id}`)
          .then(res => {
            if (res && res.data) {
              this.activity = res.data.activity;
              this.museum = res.data.museum;
              this.load();
              console.log("负责人详情:", this.activity, this.museum);
            } else {
              console.error("无效的响应数据:", res);
              ElMessage.error('获取负责人详情失败，请稍后再试');
            }
          })
          .catch(err => {
            console.error("获取负责人详情失败:", err);
          });
    },

    load(id, pageNum) { // 分页查询
      if (pageNum) {
        this.pageNum = pageNum;
      }
      request.get('/head/selectByPage', {
        params: { pageNum: this.pageNum, pageSize: this.pageSize, activity: this.activity, museum: this.museum }
      }).then(res => {
        if (res && res.data && typeof res.data === 'object') {
          this.tableData = res.data.list || [];
          this.total = res.data.total || 0;
          console.log("负责人数据:", this.tableData);
        } else {
          console.error("无效的响应数据:", res);
          ElMessage.error('获取负责人数据失败，请稍后再试');
        }
      }).catch(err => {
        console.error("获取负责人数据失败:", err);
      });
    },
  },
}
</script>

<style scoped>

</style>